package com.education.welco.controller;

import com.education.common.core.BaseController;
import com.education.common.utils.ApiReturnObject;
import com.education.utils.PageUtil;
import com.education.welco.pojo.SReport;
import com.education.welco.service.ISAnsweringCommentService;
import com.education.welco.service.ISReportService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 举报 信息操作处理
 *
 * @author d
 * @date 2022-06-25
 */
@RestController
@RequestMapping("/sReport")
public class SReportController extends BaseController {

    @Autowired
    private ISReportService sReportService;
    @Autowired
    private ISAnsweringCommentService answeringCommentService;

    /**
     * 查询举报列表-答疑评论举报-s_report表
     */
    @GetMapping("/list")
    public ApiReturnObject list(SReport sReport, Integer pageNum, Integer pageSize) {
        //if (pageNum != null && pageSize != null) {
        //    PageHelper.startPage(pageNum, pageSize);
        //}
        //List<SReport> reportList = sReportService.selectSReportListForComment(sReport);
        //return new ApiReturnObject("200", "查询成功", reportList);
        List<SReport> list = sReportService.selectSReportList(sReport);
        if (pageNum != null && pageSize != null) {
            PageUtil pageUtil = new PageUtil();
            pageUtil.pageUtil(pageNum, pageSize, list);
            return new ApiReturnObject("200", "查询成功", pageUtil);
        }
        PageInfo pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200", "查询成功", pageInfo);
    }

    /**
     * 新增保存举报
     */
    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody SReport sReport) {
        sReportService.insertSReport(sReport);
        return new ApiReturnObject("200", "添加成功", "");
    }


    /**
     * 详情举报
     */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(String id) {
        SReport result = sReportService.selectSReportById(id);
        return new ApiReturnObject("200", "查询成功", result);
    }

    /**
     * 修改保存举报
     */
    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody SReport sReport) {
        sReportService.updateSReport(sReport);
        return new ApiReturnObject("200", "修改成功", "");
    }

    /*
     *  删除举报、删除举报的评论
     *
     */

    /**
     * 删除举报  举报表的id     ckeyId 评论表的id与       creportType评论表的举报类型
     */
    @PostMapping("/del")
    public ApiReturnObject remove(@RequestBody Map map) {
        //String ids,String ckeyId,String creportType
        String ids = map.get("ids").toString();
        String ckeyId = map.get("ckeyId").toString();
        String creportType = map.get("creportType").toString();
        //删除举报表
        sReportService.deleteSReportByIds(ids);
        //删除评论表  4达人评论   5答疑评论
        if (creportType.equals("5")) {
            answeringCommentService.deleteSAnsweringCommentByIds(ckeyId);
        } else if (creportType.equals("4")) {

        }
        return new ApiReturnObject("200", "删除成功", "");
    }
}